﻿using System;

using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
    /// <summary>
    /// Summary description for AccessControl.
    /// </summary>
    public class OCVAccessControl : AccessControl
    {

        public override bool IsReadOnly
        {
            get
            {
                if (base.IsReadOnly)
                {
                    return base.IsReadOnly;
                }
                else
                {
                    if (this._currentStep == WorkTransition.OCV_CostCenterHeadApproval || this._currentStep == WorkTransition.OCV_DepartmentFNCApproval
                        || this._currentStep == WorkTransition.OCV_DepartmentHeadApproval || this._currentStep == WorkTransition.OCV_DepartmentVPApproval
                        || this._currentStep == WorkTransition.OCV_Feedback || this._currentStep == WorkTransition.OCV_Close
                        || this._currentStep == WorkTransition.OCV_SSMEEVPApproval)
                    {
                        return true;
                    }
                    else
                        return false;
                }
            }
        }

        public override bool IsAttachmentReadOnly
        {
            get
            {
                if (_state == SysDicItem.ProjectStatusFlag.NORMAL || _state == null || _state == string.Empty)
                {
                    if (this._currentStep == WorkTransition.OCV_CostCenterHeadApproval || this._currentStep == WorkTransition.OCV_DepartmentFNCApproval
                        || this._currentStep == WorkTransition.OCV_DepartmentHeadApproval || this._currentStep == WorkTransition.OCV_SSMEEVPApproval)
                    {
                        return true;
                    }
                }

                if (this._currentStep == WorkTransition.End && this._state != SysDicItem.ProjectStatusFlag.Archive)
                {
                    if (_state == SysDicItem.ProjectStatusFlag.Participation)
                        return !this._isMgrOrStaff;
                    else
                        return true;
                }
                else
                    return base.IsAttachmentReadOnly;

            }
        }

        public override bool IsButtonVisible(string name)
        {
            if (this.IsQuery)
            {
                switch (name)
                {
                    case OCVTransitionList.Copy:
                        return this.ShowCopyButton();
                        break;
                    case OCVTransitionList.Reply:
                        return this.ShowReplyButton();
                        break;
                    case OCVTransitionList.Save:
                        return this.ShowSaveButton();
                        break;
                    default:
                        return false;
                }
            }
            else
            {
                switch (name)
                {
                    case OCVTransitionList.Copy:
                        return this.ShowCopyButton();
                        break;
                    case OCVTransitionList.Reply:
                        return this.ShowReplyButton();
                        break;
                    default:
                        switch (this._currentStep)
                        {
                            case WorkTransition.Draft:
                                if (name == OCVTransitionList.Submit || name == OCVTransitionList.Save)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Apply:
                                if (name == OCVTransitionList.Submit || name == OCVTransitionList.Save || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_ReApply:
                                if (name == OCVTransitionList.Submit || name == OCVTransitionList.Save || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Assignment:
                                if (name == OCVTransitionList.Assign || name == OCVTransitionList.Reject || name == OCVTransitionList.Save
                                    || name == OCVTransitionList.Check || name == OCVTransitionList.Query || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Check:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Check || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Save || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_CostCenterHeadApproval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_DepartmentVPApproval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_SSMEEVPApproval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Lv1Approval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Lv2Approval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Lv3Approval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;

                            case WorkTransition.OCV_Lv4Approval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_DepartmentHeadApproval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_DepartmentFNCApproval:
                                if (name == OCVTransitionList.Reject || name == OCVTransitionList.Approve || name == OCVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Feedback:
                                if (name == OCVTransitionList.Save || name == OCVTransitionList.Submit //|| name == CVTransitionList.Query
                                    || name == OCVTransitionList.Reply)
                                    return true;
                                else
                                    return false;
                            case WorkTransition.OCV_Close:
                                if (name == OCVTransitionList.Close)// || name == CVTransitionList.Query)
                                    return true;
                                else
                                    return false;
                        }
                        return false;
                        break;
                }
            }
        }

    }
}
